using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using Rapier.Kodachi.Shared;
using System.IO;

namespace Rapier.Kodachi.Firefox
{
    public partial class Settings : Form
    {
        private Host host;
        public bool UseSpecific
        {
            get { return !FirefoxPlugin.FirefoxSettings.UseDefault; }
            set { FirefoxPlugin.FirefoxSettings.UseDefault = !value; }
        }

        public Settings(Host host)
        {
            InitializeComponent();
            SetupBinding();
            this.host = host;

            bBrowse.Click += new EventHandler(bBrowse_Click);
        }

        private void SetupBinding()
        {
            bBrowse.DataBindings.Add("Enabled", radioSpecific, "Checked", false, DataSourceUpdateMode.OnPropertyChanged);
            bBrowse.DataBindings.Add("Text", FirefoxPlugin.FirefoxSettings, "SpecificFirefoxProfilePath", true, DataSourceUpdateMode.OnPropertyChanged);
            radioDefault.DataBindings.Add("Checked", FirefoxPlugin.FirefoxSettings, "UseDefault", false, DataSourceUpdateMode.OnPropertyChanged);
            radioSpecific.DataBindings.Add("Checked", this, "UseSpecific", false, DataSourceUpdateMode.OnPropertyChanged);
        }

        void bBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                bBrowse.Text = ofd.FileName;
            }
        }

        private void bClose_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}